﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using SharpShare.Storage;
using SharpShare.Activation;
using System.ComponentModel;

namespace SharpShare.Configuration {
    [CollectableElement(AddElementName = "service")]
    public abstract class ServiceElement : ConfigurationElement, IKeyedElement, IExtension {
        [Category("(General)")]
        [Description("The name of this service used to identify and reference this instance in the configuration.")]
        [ConfigurationProperty("name", IsKey = true, IsRequired = true)]
        public string Name {
            get {
                return (string)this["name"];
            }
            set {
                this["name"] = value;
            }
        }

        [Browsable(false)]
        public IKeyedElementCollection<ShareElement> Shares {
            get {
                return (IKeyedElementCollection<ShareElement>)this["shares"];
            }
        }

        public abstract IShareService CreateService(IConfigurationContext context);

        #region IKeyedElement Members

        string IKeyedElement.Key {
            get { return this.Name; }
        }

        #endregion
    }

    public abstract class ServiceElement<TShare> : ServiceElement
        where TShare : ShareElement, IKeyedElement, new() {

        public ServiceElement() {

        }

        [Browsable(false)]
        [ConfigurationProperty("shares")]
        public new GenericElementCollection<TShare> Shares {
            get {
                return (GenericElementCollection<TShare>)this["shares"];
            }
        }
    }
}
